load('cca_data.mat')

% Variables
train = randperm(1000,50); %choosing 50 items for training set
test = 1:length(class) ; %test set (left out data)
test(train) = [];
XY = [X Y]; % concatenated data
[cX cY] = canoncorr(X,Y); % performing cca
canonXY = [X*cX Y*cY]; % linear combination with correlation coefficients


% Train Models
modelSingleX = regress(class(train),X(train,:)); % training a model based on view1 (model 1)
modelSingleY = regress(class(train),Y(train,:)); % training a model based on view2 (model 2)
modelXY = regress(class(train),XY(train,:)); % training a model based on concatenation of both views (model 3)
modelCanonXY = regress(class(train),canonXY(train,:)); % training a model based on the linear combination of views (model 4)


% MSE for each model
errorSingleX = mean((X(test,:) * modelSingleX - class(test)) .^2 ); % error for model 1
errorSingleY = mean((Y(test,:) * modelSingleY - class(test)) .^2 ); % error for model 2
errorXY = mean((XY(test,:) * modelXY - class(test)) .^2 ); % error for model 3
errorCanonXY = mean((canonXY(test,:) * modelCanonXY - class(test)) .^2 ); % error for model 4




errorSingleX
errorSingleY
errorXY
errorCanonXY